
local function _max(array)
    if next(array) == nil then
        return 0
    elseif #array == 1 then
        return array[1]
    elseif #array == 2 then
        return math.max(array[1], array[2])
    else
        return math.max(array[1], _max(table.move(array, 2, #array, 1, {})))
    end
end

local function test()
    local max = 5
    local arr = {}
    for i=1, max do
        arr[#arr+1] = i
    end

    local max2 = _max(arr)
    assert(max == max2)
end

test()

